Skip to content

Read local Postgres settings from the assembled env, not process.env - #164

Closed
16francej wants to merge 2 commits into
mainfrom
fix/dev-instance-postgres-env
Closed

Read local Postgres settings from the assembled env, not process.env#164
16francej wants to merge 2 commits into
mainfrom
fix/dev-instance-postgres-env

Conversation

@16francej

@16francej 16francej commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Problem

dev-instance up failed with could not connect to DATABASE_URL: password authentication failed for user \"postgres\" on a machine whose ~/.config/qm/dev.env sets DEV_INSTANCE_POSTGRES_PORT=55433.

The CLI spawns the supervisor with only the caller's env (scripts/dev/cli.ts); dev.env is merged into assembled.env later by assembleEnv(). But ensureLocalPostgres() read DEV_INSTANCE_POSTGRES_* from process.env, so dev.env settings never reached it. It defaulted to port 55432 — which on this machine belongs to a different Postgres container with a different password — while the qm-dev-postgres container name check passed, producing the misleading auth failure.

Fix

ensureLocalPostgres() takes the env record and the supervisor passes assembled.env (which already layers caller env over dev.env). No default-to-process.env fallback, so the resolution order is single-sourced.

Verified

  • Before (on main): up fails as above unless DEV_INSTANCE_POSTGRES_PORT=55433 is exported manually.
  • After: up boots clean with no manual export — canary round-trips, core runs store=postgres against the dev.env-configured container. Torn down after.
  • dev-cli-lib and dev-supervisor-child tests, typecheck, lint, format all pass.

Found while live-QAing #160.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

The supervisor is spawned with only the caller's env; dev.env is merged
into assembled.env later by assembleEnv(). ensureLocalPostgres() read
DEV_INSTANCE_POSTGRES_* from process.env, so a port/container/password
configured in dev.env never reached it — it defaulted to 55432 and, on a
machine where that port belongs to a different Postgres container, up
failed with 'password authentication failed for user postgres'. Thread
the assembled env through instead.
@16francej 16francej added code-pr Code submitted instead of an ADR bug Something isn't working labels Aug 4, 2026
@ReganBell

Copy link
Copy Markdown
Collaborator

Thanks for the flag! Under new CONTRIBUTING we're handling bugs as issues and doing human-written, informal ADRs for features. Moving this to an issue. You'll be credited as co-author if a fix ships.

#221

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working code-pr Code submitted instead of an ADR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants